package com.coin.controller;

import com.coin.domain.CoinConfig;
import com.coin.model.R;
import com.coin.service.CoinConfigService;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @Auther: 李 力
 * @Date: 2025/6/12
 * @Description: com.coin.controller
 * @version: 1.0
 */
@Api(tags = "币种配置的控制器")
@RestController
@RequestMapping("/coinConfigs")
public class CoinConfigController {

    @Autowired
    private CoinConfigService coinConfigService;

    /**
     * @Description: 查询币种的配置信息
     * @Author: 李 力
     * @Date: 2025/6/12
     * @Param:
     * @return: R
     */
    @GetMapping("/info/{coinId}")
    @ApiOperation(value = "查询币种的配置信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "coinId", value = "币种的id值")
    })
    public R<CoinConfig> getCoinConfig(@PathVariable("coinId") Long coinId) {
        CoinConfig coinConfig = coinConfigService.findByCoinId(coinId);
        return R.ok(coinConfig);
    }

    /**
     * @Description: 币种配置的修改操作
     * @Author: 李 力
     * @Date: 2025/6/12
     * @Param:
     * @return: R
     */
    @PutMapping
    @ApiOperation(value = "币种配置的修改操作")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "coinConfig", value = "coinConfig的json数据")
    })
    public R update(@RequestBody @Validated CoinConfig coinConfig) {
        boolean saveOrUpdate = coinConfigService.updateOrSave(coinConfig);
        return saveOrUpdate ? R.ok(true, "操作成功") : R.fail("操作失败");
    }
}
